/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Trabalho3.RegrasPasswordChecker02;

import Trabalho3.RuleFactory;

/**
 *
 * @author geraldo
 */
public class RegraBonusDigitos implements RuleFactory{
    private final int FATOR_BONUS_DIGITOS = 4;
    String password;

    public RegraBonusDigitos(String password) {
        this.password = password;
    }
    
    
    @Override
    public int calcularRegra() {
           int total = this.somarDigitos();
        return (total<password.length() && total>0)? total* FATOR_BONUS_DIGITOS:0;
    }
    
    public int somarDigitos() {
        int total = 0;
        for (char c : password.toCharArray()) {
            if (Character.isDigit(c)) {
                total++;
            }
        }
        return total;
    }
}
